package softwaredepartment.zxit.com.pt_3280cinandroid;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class CallMeActivity extends AppCompatActivity implements View.OnClickListener {

    private Button hang_up, approve, cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_me);
        init();
    }

    private void init() {
        hang_up = (Button) findViewById(R.id.hang_up);
        approve = (Button) findViewById(R.id.approve);
        cancel = (Button) findViewById(R.id.cancel);

        hang_up.setOnClickListener(this);
        approve.setOnClickListener(this);
        cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        SharedPreferences sharedPreferences = getSharedPreferences("CallEachOtherBasicInfo",
                Activity.MODE_PRIVATE);
        //sharedPreferences.getString("NOW_STATE", null).equals("1");
        SharedPreferences.Editor editor = sharedPreferences.edit();
        switch (v.getId()) {
            case R.id.hang_up:
                //用putString的方法保存数据
                editor.putString("CLIENT_IP", null);
                editor.putString("NOW_STATE", "3");
                //提交当前数据
                editor.commit();
                finish();
                break;
            case R.id.cancel:
                //用putString的方法保存数据
                editor.putString("CLIENT_IP", null);
                editor.putString("NOW_STATE", "0");
                //提交当前数据
                editor.commit();
                finish();
                break;
            case R.id.approve:
                //用putString的方法保存数据
                editor.putString("NOW_STATE", "2");
                //提交当前数据
                editor.commit();
                //启动语音线程
                break;
            default:
                break;
        }
    }
}
